package private

import (
	"dc-go/global"
	"dc-go/model"
	"dc-go/utils"

	"github.com/gin-gonic/gin"
	"go.uber.org/zap"
)

type ApiSqlSqlparam struct{}

func (a *ApiSqlSqlparam) GetSqlSqlparamList(c *gin.Context) {
	var sqlCode model.RequestSqlCode
	if err := model.RequestShouldBindJSON(c, &sqlCode); err != nil {
		return
	}
	if sqlparamMenuList, err := servicePrivate.ServiceSqlSqlparam.GetSqlSqlparamList(&sqlCode); err != nil {
		global.DcLogger.Error("获取Sql和Sql参数关系列表失败! ", zap.Any("err", err))
		model.ResponseErrorMessage("获取Sql和Sql参数关系列表失败, "+err.Error(), c)
	} else {
		model.ResponseSuccessData(gin.H{"records": sqlparamMenuList}, c)
	}
}

func (a *ApiSqlSqlparam) EditSqlSqlparam(c *gin.Context) {
	var sqlSqlparam model.RequestSqlSqlparamEdit2
	if err := model.RequestShouldBindJSON(c, &sqlSqlparam); err != nil {
		return
	}
	empeeAcct := utils.GetEmpeeAcct(c)
	if err := servicePrivate.ServiceSqlSqlparam.EditSqlSqlparam(&sqlSqlparam, empeeAcct); err != nil {
		global.DcLogger.Error("编辑Sql和Sql参数关系失败! ", zap.Any("err", err))
		model.ResponseErrorMessage("编辑Sql和Sql参数关系失败, "+err.Error(), c)
	} else {
		global.DcLogger.Warn(utils.GetEmpeeAcct(c) + "编辑Sql和Sql参数关系成功! ")
		model.ResponseSuccessMessage("编辑Sql和Sql参数关系成功! ", c)
	}
}
